/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[TestConsole.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package io.api;

import java.io.Console;
import java.util.Arrays;

/**
 * java.io.Console测试
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class TestConsole {

	public static void main(String[] args) {
		Console console = System.console();
		// 判断是否有控制台的使用权限
		if (console != null) {
			System.out.println("请输入用户名:");
			String username = console.readLine();

			System.out.println("请输入密码:");
			// 读取密码, 输入时不显示
			char[] pwd = console.readPassword();

			System.out.println("用户名: " + username + "\t密码: " + Arrays.toString(pwd));
		} else {
			System.out.println("Console is not available.");
		}
	}
}
